//
//  ClassificationViewController.m
//  TodayPlayWhat
//
//  Created by 作者 on 16-5-19.
//  Copyright (c) 2016年 HCY. All rights reserved.
//

#import "ClassificationViewController.h"
#import "OtherTableViewCell.h"
#define SCREEN_WIDTH self.view.bounds.size.width
#define SCREEN_HEIGHT  self.view.bounds.size.height

@interface ClassificationViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation ClassificationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    
    [_classTable registerNib:[UINib nibWithNibName:@"OtherTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    [self creatButton];
    [self scrollLayout];
   
    
}



#pragma mark UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    OtherTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    
    return cell;
}

//
//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
//{
//    return 40;
//}

//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
//{
//    UIView *v =[[UIView alloc]init];
//    v.backgroundColor  =[UIColor groupTableViewBackgroundColor];
//    
//  
//    
//    
//    
//    return v;
//}


- (void)headerButtonAction:(id)sender
{
    UIButton * button = (UIButton *)sender;
    switch (button.tag) {
        case 1:
        {
            
        }
            break;
        case 2:
        {
            
        }
            break;
        case 3:
        {
            
        }
            break;
        default:
            break;
    }
}


- (void)creatButton
{
    NSArray * titleArray =@[@"全部分类",@"全部时间",@"推荐"];
    
    
    for (int i = 0; i < 3; i ++) {
        UIButton * viewBtn =[UIButton buttonWithType:(UIButtonTypeSystem)];
        viewBtn.frame = CGRectMake(5+(100+30)*i, 5, 100, 30);
        
        //        viewBtn.backgroundColor =[UIColor blueColor];
        [viewBtn setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        
        [viewBtn setTitle:titleArray[i] forState:(UIControlStateNormal)];
        
        [viewBtn addTarget:self action:@selector(headerButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
        viewBtn.tag = i + 1;
        [_topView addSubview:viewBtn];
    }
}

- (void)scrollLayout
{
   
    _classScrollView.contentSize = CGSizeMake(SCREEN_WIDTH /6 *9 , 50);
   
        
     NSArray *array =@[@"分类",@"全部",@"音乐",@"戏剧",@"曲艺",@"休闲",@"聚会",@"展览",@"电影",@"讲座",@"周边游",@"运动",@"亲子",@"公益"];
    
    for (int i = 0; i < 14; i ++) {
       
        float titleWidth =[self getWidthwithStr:array[i]];
     
        UIButton * button =[UIButton buttonWithType:(UIButtonTypeCustom)];
        button.titleLabel.font =[UIFont systemFontOfSize:14];
        NSLog(@"width %f,array%@",titleWidth,array[i]);
        
        button.frame =CGRectMake(5+(60+5)*i,5, titleWidth, 35);
    
      
        
        [button setTitle:array[i] forState:(UIControlStateNormal)];
        
        button.tag = i+100;
        [button addTarget:self action:@selector(selectButtonClick:) forControlEvents:(UIControlEventTouchUpInside)];
        
        [_classScrollView  addSubview:button];
       
    }
   
 }
- (CGFloat)getWidthwithStr:(NSString *)title
{
    CGRect rect =[title boundingRectWithSize:(CGSizeMake(SCREEN_WIDTH/6, 35)) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil];
    return rect.size.width+10;
 }

- (void)selectButtonClick:(id)sender
{
    UIButton *button =(UIButton *)sender;
    //点击按钮 view移动
  
    UIView *titleView =[[UIView alloc]initWithFrame:(CGRectMake(button.frame.origin.x, 40, button.bounds.size.width, 2))];
    titleView.backgroundColor =[UIColor redColor];
    [_classScrollView addSubview:titleView];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
